package com.hr.reactive.flux;

import com.hr.reactive.common.Utils;
import reactor.core.publisher.Flux;

import java.util.stream.IntStream;

/**
 * @author Administrator
 */
public class Lec10FluxTakeOperator {
    public static void main(String[] args) {
        IntStream.rangeClosed(1, 10).limit(3).forEach(System.out::println);
        takeUntil();
    }

    private static void take() {
        Flux.range(1, 10).log("take").take(30).log("sub").subscribe(Utils.subscriber());
    }

    private static void takeWhile() {
        Flux.range(1, 10).log("take").takeWhile(i -> i < 5).log("sub").subscribe(Utils.subscriber());
    }

    //当条件满足时会停止
    private static void takeUntil() {
        Flux.range(1, 10).log("take").takeUntil(i -> i < 5).log("sub").subscribe(Utils.subscriber());
    }
}
